<?php
define('YD_TRUE', true);
/*
// @author : lael
// blog : http://hi.baidu.com/lael80
// http://www.gzyd.net
// all right reserved.
*/

@header('content-Type: text/html; charset=utf-8');
set_time_limit(0);
ini_set('display_errors', 'On');
error_reporting(7);
if(function_exists('date_default_timezone_set'))date_default_timezone_set('Etc/GMT-8');
session_start();

define('YD_ROOT', str_replace('\\', '/', dirname(__FILE__)).'/');//当前目录绝对路径
define('YD_PATH', './');//当前目录相对路径
define('YD_URL', substr($_SERVER['PHP_SELF'], 0, -1 * strlen('index.php')));//当前URL路径
$GLOBALS['YD_SDK'] = array();//全局变量

include_once YD_ROOT.'helpers/function.php';
//magic_quotes_gpc = On
$init_mqg = get_magic_quotes_gpc();
if(!$init_mqg){
    add_mqg($_POST);
    add_mqg($_GET);
}
//core目录的文件需自己include
include_once YD_ROOT.'core/common.php';
include_once YD_ROOT.'core/api.php';
include_once YD_ROOT.'core/admin.php';

$con = array_filter(explode('/', trim(strtolower($_GET['con']), '/')));
$act = 'index';
if(!file_exists(YD_ROOT.'controllers/'.implode('/', $con).'.php')){
	$act = end($con);
	array_pop($con);
}
$con = implode('/', $con);
if(!trim($con, '/'))exitjson(-1, 'Controller Not Exists');
if(!file_exists(YD_ROOT.'controllers/'.$con.'.php'))exitjson(-1, 'Controller Not Exists');
$GLOBALS['YD_SDK']['con'] = $con;
$GLOBALS['YD_SDK']['act'] = $act;
include_once(YD_ROOT.'controllers/'.$con.'.php');
$con = '\ydsdk\controllers\\'.str_replace('/', '\\', $con);
$object = new $con();
if(!is_callable(array($object, $act)))exitjson(-1, 'Action Not Exists');
$object->$act();
?>